<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<style>

.face-input { border: solid 0px #ddd !important;}
.face-input:hover{border:0px solid #fff !important;}
.face-input.focus{border-color: rgba(255,255,255,0) !important;box-shadow: 0 0 0 rgba(0,0,0,0) inset,0 0 0 rgba(0,0,0,0) !important;}
.row-textarea{margin-top:100px !important; display:none !important;}
.row-textarea-block{ display:block !important;}
</style>
<#include "lib/lib.html" />
<title>接口测试</title>
</head>
<body class="pos-r">
<div style="margin-left:150px;">
	<div>
		<form  method="get" class="form form-horizontal" id="interfaceForm" id="form-user-character-add" action="${basePath}/intefaces/interfaceTest.do?type=1">
			<input type="hidden" id="id" name="id" value="${(interfaceInfo.id)!''}"/>
			<input type="hidden" name="funId" value="${(interfaceInfo.funId)!''}"/>
			<input type="hidden" name="appId" value="${(interfaceInfo.appId)!''}"/>
			<div class="row cl">
				<label class="form-label col-2">接口名称：</label>
				<div class="formControls col-8">
					<input type="text" class="face-input input-text" name="" value="${(interfaceInfo.interfaceName)!''}" placeholder=""  nullmsg="接口名称不能为空" readonly style="width:300px;">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-2">请求类型：</label>
				<div class="formControls col-8">
					<span class="select-box" style="width: 100px;">
						<select id="select1" class="select" size="1" name="reqType" value="${(interfaceInfo.reqType)!''}">
							<option value="${(interfaceInfo.reqType)!''}">${interfaceInfo.reqType!}</option>
							<!-- <option value="post">post</option> -->
						</select>
					</span>
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-2">请求url：</label>
				<div class="formControls col-8">
					<input type="text" class="input-text" id="reqUrl" name="reqUrl" value="" placeholder=""  nullmsg="请求url不能为空"  style="width:300px;">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-2">接口描述：</label>
				<div class="formControls col-8">
					<input type="text" class="face-input input-text" name="" value="${(interfaceInfo.interfaceDesc)!''}" placeholder=""  nullmsg="接口描述不能为空" readonly style="width:300px;">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-2">接口请求参数：</label>
				<div class="formControls col-8 faceControls">
					<#if paramList??&&paramList?size gt 0>
					<#list paramList as pl>
						<input type="text" class="input-text demo111" name="paramName" value="${(pl.paramName)!''}" placeholder="" style="width:150px" readonly> - 
						<input type="text" class="input-text" name="interfaceValue" value="" placeholder=""  nullmsg="接口描述不能为空" style="width:300px"><br>
					</#list>
					</#if>
				</div>
			</div>
			<div class="row cl">
				<div class="col-10 col-offset-2">
					<button type="button" onclick="_test()" class="btn btn-success radius" id="admin-role-save">确定</button>
				</div>
			</div>
			<!-- <div class="row-textarea  row cl">
				<label class="form-label col-2">接口测试返回结果：</label>
				<div class="formControls col-8">
					<textarea cols="120" rows="30">${resultInfo!}</textarea>
				</div>
			</div> -->
			<#if resultInfo??> 
			<div class="row cl">
				<label class="form-label col-2">接口测试JSON返回结果：</label>
				<div class="formControls col-8">
					<textarea cols="120" rows="30" name="jsonResult" id="jsonResult"></textarea>
				</div>
			</div>
			</#if>
		</form>
		</div>
	</div>
	<script type="text/javascript">
	var index = '${(interfaceInfo.reqUrl)}'.indexOf('http');
	if(index >= 0){
	      $("#reqUrl").val('${interfaceInfo.reqUrl}');
	 }else{
		 $("#reqUrl").val('${basePath}'+'/'+'${(interfaceInfo.reqUrl)}');
	 }
	var formatJsonStr = getFormatJsonStrFromString('${resultInfo}');
	$("#jsonResult").val(formatJsonStr);
	function getFormatJsonStrFromString(jsonStr){
        var res="";
        for(var i=0,j=0,k=0,ii,ele;i<jsonStr.length;i++)
        {//k:缩进，j:""个数
            ele=jsonStr.charAt(i);
            if(j%2==0&&ele=="}")
            {
                k--;                
                for(ii=0;ii<k;ii++) ele="    "+ele;
                ele="\n"+ele;
            }
            else if(j%2==0&&ele=="{")
            {
                ele+="\n";
                k++;            
                for(ii=0;ii<k;ii++) ele+="    ";
            }
            else if(j%2==0&&ele==",")
            {
                ele+="\n";
                for(ii=0;ii<k;ii++) ele+="    ";
            }
            else if(ele=="\"") j++;
            res+=ele;               
        }
        return res;
    }
	
	
		function _test(){
			//获取值URL
			var url=$("#reqUrl").val();
			var keyValue="";
			$(".faceControls .demo111").each(function(){
				var valueKey = $(this).val();
				var valueText = $(this).next("input").val();
				//判断参数值是否为空
				if(valueText!=null||valueText!=""){
					keyValue=keyValue+valueKey+"="+valueText+"&";
				}
			})
			if(keyValue!=null||keyValue!=""||keyValue.length>0){
				keyValue=keyValue.substring(0,keyValue.length-1);
				url=url+"?"+keyValue;
			}
			window.location.href="${basePath}/intefaces/interfaceTest.do?type=1&id="+$("#id").val()+"&url="+url;
			$(".row-textarea").addClass("row-textarea-block")
		}
	</script>
</body>
</html>